// pages/personal/team/vip.js
const app = getApp();
const total = 60
var count = total;

Page({

    /**
     * 页面的初始数据
     */
    data: {
        message: false,
        verifyInfo: '获取验证码'
    },
    bindMask: function () {
        this.setData({ message: false })
    },

    phoneInput: function (e) {
        this.setData({
            phone: e.detail.value
        })
    },
    bindGetcode: function () {

        if (count != total) {
            return
        }
        if (!this.data.phone.match(/^1[3|4|5|7|8][0-9]\d{4,8}$/g)) {
            wx.showModal({
                title: "请输入正确的手机号"
            });
            return false;
        } else {
            app.http.post('member/send-verify', {
                data: {
                    phone: this.data.phone
                },
            }).then(res => {
                //成功
                var that = this
                count--;
                var timer = setInterval(function () {
                    count--;
                    if (count >= 1) {
                        that.setData({
                            verifyInfo: count + 's'
                        })
                    } else {
                        that.setData({
                            verifyInfo: '重新获取',
                        })
                        count = total
                        clearInterval(timer);
                    }
                }, 1000);
            }).catch(err => {
                //失败
            })

        }
    },
    codeInput: function (e) {
        this.setData({ code: e.detail.value })
    },
    bindSure: function () {
        if (!this.data.phone || !this.data.code) {
            return
        } else {
            app.http.post('member/vip', {
                data: { num: this.data.code, phone: this.data.phone }
            }).then(res => {
                var jspay = res.data.js;
                jspay.success = function () {
                    wx.showToast({
                        title: "支付成功",
                    });
                    wx.navigateBack()
                }
                jspay.fail = function () {
                    app.wxToast.error("支付失败")
                }

                wx.requestPayment(jspay)

            }).catch(err => {
                app.wxToast.error(err.message)
            })
        }


    },


    bindBay: function () {
        this.setData({ message: true })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})